
<template>
  <a-card>
    <p style="font-size: 18px; text-align: center">销售出库单</p>
    <br />
    <a-form-model :model="Form" v-bind="layout"
      ><!-- 顶部的信息  -->
      <a-row>
        <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="单据号">
            <div>{{ Form.document }}</div>
          </a-form-model-item>
        </a-col>

        <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="单据日期">
            <div>{{ Form.document_date }}</div>
          </a-form-model-item>
        </a-col>

        <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="发货仓库">
            <div>{{ Form.depotName }}</div>
          </a-form-model-item>
        </a-col>

        <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="申请部门">
            <div>{{ Form.department }}</div>
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="客户">
            <div>{{ Form.client }}</div>
          </a-form-model-item>
        </a-col>
        <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="收发类别">
            <div>{{ Form.sendReceiveType }}</div>
          </a-form-model-item>
        </a-col>

        <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="库管员">
            <div>{{ Form.cwhsmanagerid_dictText }}</div>
          </a-form-model-item>
        </a-col>

        <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="库存组织">
            <div>{{ Form.pkCalbody_dictText }}</div>
          </a-form-model-item>
        </a-col>
      </a-row>

      <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
        <a-form-model-item label="业务流程">
          <div>{{ Form.cbiztype_dictText }}</div>
        </a-form-model-item>
      </a-col>
    </a-form-model>

    <a-table
      :columns="columns"
      :data-source="DataSource"
      style="margin-top: 10px"
      :pagination="false"
      :scroll="autoSize"
    >
    </a-table>

    <div style="margin-top: 20px">
      <!-- 单据 -->
      <a-form-model :model="Form" v-bind="layout"
        ><!-- 顶部的信息 -->
        <a-row>
          <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
            <a-form-model-item label="负责人">
              <div>{{ Form.responsiblePerson }}</div>
            </a-form-model-item>
          </a-col>

          <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
            <a-form-model-item label="审核人">
              <div>{{ Form.inspector }}</div>
            </a-form-model-item>
          </a-col>

          <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
            <a-form-model-item label="审核日期">
              <div>{{ Form.balance }}</div>
            </a-form-model-item>
          </a-col>

          <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
            <a-form-model-item label="制单人">
              <div>{{ Form.singleProducer }}</div>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>

      <!-- 提交按钮组  
      1. 能审核提交的人是不能点击保存的
      2. 能保存的人是不能审核和提交的
      -->
      <div style="margin-top: 20px">
        <center>
          <a-button type="primary" style="margin-right: 20px" @click="goPrint">
            打印
          </a-button>

          <a-button style="margin-right: 20px" disabled> 保存 </a-button>

          <a-button
            @click="Examine"
            style="margin-right: 20px"
            :disabled="!alreadyCheckTag"
          >
            审核
          </a-button>

          <a-button
            type="primary"
            style="margin-right: 20px"
            @click="antiExamine"
            :disabled="AntcanCheck"
          >
            反审核
          </a-button>
          <a-button
            type="primary"
            @click="save_u8c"
            :disabled="!alreadyAsyncTag"
          >
            同步至用友
          </a-button>
        </center>
      </div>
    </div>

    <div style="display: none">
      <div id="printCons" style="width: 85%; margin: 0 auto; color: black">
        <!-- // 标题 -->
        <div
          id="style1"
          style="
            display: flex;
            flex-direction: row;
            justify-content: flex-start;
            height: 30px;
            line-height: 20px;
          "
        >
          <div style="margin-left: 10px">
            <div>单据号: {{ Form.document }}</div>
          </div>

          <div style="margin-left: 10px">
            <div>日期: {{ Form.document_date }}</div>
          </div>

          <div style="margin-left: 10px">
            <div>仓库: {{ Form.depotName }}</div>
          </div>
        </div>
        <div
          id="style1"
          style="
            display: flex;
            flex-direction: row;
            justify-content: flex-start;
            height: 30px;
            line-height: 20px;
          "
        >
          <div style="margin-left: 10px">
            <div>部门: {{ Form.department }}</div>
          </div>
          <div style="margin-left: 80px">
            <div>收发类别: {{ Form.sendReceiveType }}</div>
          </div>

          <div style="margin-left: 80px">
            <div>库管员: {{ Form.cwhsmanagerid_dictText }}</div>
          </div>
        </div>
        <div
          id="style1"
          style="
            display: flex;
            flex-direction: row;
            justify-content: flex-start;
            height: 30px;
            line-height: 20px;
          "
        >
          <div style="margin-left: 10px">
            <div>客户: {{ Form.client }}</div>
          </div>
        </div>
        <!-- 表格 -->
        <div class="print-table" style="margin-top: 0px">
          <table
            style="width: 100%; text-align: center; border-collapse: collapse"
            border="0"
            cellspacing="0"
            cellpadding="0"
          >
            <tr>
              <th>存货名称</th>
              <th>规格</th>
              <th>单位</th>
              <th>数量</th>
              <th>金额</th>
              <th>备注</th>
            </tr>
            <tr v-for="(item, index) in printDataSource" :key="index">
              <th>{{ item.inventoryName }}</th>
              <th>{{ item.standardModel }}</th>
              <th>{{ item.unit }}</th>
              <th>{{ item.quantity }}</th>
              <th>{{ item.money }}</th>
              <th>{{ item.remark }}</th>
            </tr>
          </table>
        </div>

        <!-- 尾部信息 -->
        <div
          style="
            display: flex;
            flex-direction: row;
            justify-content: flex-start;
            height: 30px;
            line-height: 30px;
          "
        >
          <div style="margin-left: 15px; size: 10px">
            制单人： {{ Form.singleProducer }}
          </div>
          <div style="margin-left: 60px; size: 10px">
            审核人： {{ Form.inspector }}
          </div>
        </div>
      </div>
    </div>
  </a-card>
</template>

<script>
import { CommonAjax } from "@/services/modules/common";
const comHttp = new CommonAjax(); // 公用接口
import moment from "moment";
import axios from "axios";

import printJS from "print-js";

let columns = [
  {
    title: "序号",
    dataIndex: "key",
    key: "key",
    align: "center",
    width: "80px",
  },
  {
    title: "仓库编码",
    key: "depotNo",
    dataIndex: "depotNo",
    align: "center",
  },
  {
    title: "仓库名称",
    key: "depotName",
    dataIndex: "depotName",
    align: "center",
  },
  // {
  //   title: "库位",
  //   key: "depotLocation",
  //   dataIndex: "depotLocation",
  //   align: "center",
  // },
  {
    title: "仓位",
    key: "position_dictText",
    dataIndex: "position_dictText",
    align: "center",
  },
  // {
  //   title: "所属单位",
  //   key: "storageUnit",
  //   dataIndex: "storageUnit",
  //   align: "center",
  // },
  {
    title: "存货编码",
    dataIndex: "inventoryNo",
    key: "inventoryNo",
    align: "center",
  },
  {
    title: "存货名称",
    dataIndex: "inventoryName",
    key: "inventoryName",
    align: "center",
  },
  {
    title: "规格型号",
    dataIndex: "standardModel",
    key: "standardModel",
    align: "center",
  },
  {
    title: "单位",
    key: "unit",
    dataIndex: "unit",
    align: "center",
  },
  {
    title: "辅助单位",
    key: "auxiliaryUnit",
    dataIndex: "auxiliaryUnit",
    align: "center",
  },
  {
    title: "出库数量",
    key: "quantity",
    dataIndex: "quantity",
    align: "center",
  },
  // {
  //   title: "单价",
  //   key: "unitPrice",
  //   dataIndex: "unitPrice",
  //   align: "center",
  // },
  // {
  //   title: "金额",
  //   key: "money",
  //   dataIndex: "money",
  //   align: "center",
  // },
  {
    title: "源单单号",
    key: "sourceNumber",
    dataIndex: "sourceNumber",
    align: "center",
  },
  {
    title: "批次号",
    key: "batchNumber",
    dataIndex: "batchNumber",
    align: "center",
  },
  {
    title: "是否赠品",
    key: "giveaway",
    dataIndex: "giveaway",
    align: "center",
    width: "120px",
  },
  {
    title: "出库日期",
    key: "deliveryDate",
    dataIndex: "deliveryDate",
    align: "center",
  },
  {
    title: "货架",
    dataIndex: "goodsShelves",
    key: "goodsShelves",
    align: "center",
  },
  {
    title: "备注",
    dataIndex: "remark",
    key: "remark",
    align: "center",
  },
];
export default {
  data() {
    return {
      u8c_array: [], //u8c传递数据表格的数据源
      arr: [], //销售订单子表
      arrOut: [], //销售出库单子表
      GeneralBillVO_46: [], //需给用友传递的data
      ayyanyany: [], //销售订单主表
      ayyanyanyOut: [], //销售出库单主表
      dataList: [], //u8c全部数据
      AntcanCheck: true,
      Form: {
        id: "", // id
        document: "", // 单据号
        document_date: "", // 单据日期
        depotName: "", // 仓库名称
        depotNo: "", // 仓库编号
        depotId: "", // 仓库Id
        storageUnit: "", // 所属单位名称
        storageUnitId: "", // 所属单位Id
        storageUnitNo: "", // 所属单位编号
        department: "", // 部门名称
        deptId: "", // 部门id
        client: "", // 客户名称
        clientId: "", // 客户Id
        sendReceiveType: "", // 收发类别名称
        sendReceiveTypeId: "", // 收发类别Id

        responsiblePerson: "", // 负责人名称
        responsiblePersonId: "", // 负责人Id
        inspector: "", // 审核人名称
        inspectorId: "", // 审核人Id
        balance: "", // 审核日期
        singleProducer: "", // 制单人名称
        singleProducerId: "", // 制单人Id
        cbiztype_dictText: "", // 业务流程名称
        auditMark: 2,
      },

      saleForm: {},
      // 格式
      layout: {
        labelCol: { span: 8 },
        wrapperCol: { span: 15 },
      },

      columns,
      DataSource: [],
      autoSize: {
        x: 3500,
        y: 670,
      },
      alreadyCheckTag: true, // 可以审核
      alreadyRecordTag: true, // 可以记账
      alreadyAsyncTag: true, // 可以同步

      printDataSource: [],
    };
  },
  mounted() {
    this.getSaleInfoById();
    this.getRouterParam();
  },
  watch: {
    $route(to) {
      let id = to.query.Id;
      this.setInitInfo(id);
    },
  },

  methods: {
    // 反审核
    async antiExamine() {
      // 判断是否同步，没有同步的话，直接反审核
      if (this.Form.isSynchronized == "未同步") {
        this.updateExamine();
        this.update_audit("已反审核");
      } else {
        let fbillflag = await this.checkSaleStatus(); // 查询销售出库状态
        console.log("状态", fbillflag);
        if (fbillflag == 4) {
          this.$message.error("已签字，反审核失败！");
        } else if (fbillflag == 3) {
          let signature = await this.cancelSignature(); // 取消签字
          if (signature == "success") {
            let deleteFlag = await this.deleteSaleOutStorageOrder(); // 刪除銷售出庫單
            if (deleteFlag == "success") {
              let orderUnapprove = await this.orderUnapprove(); // 销售订单弃审
              if (orderUnapprove == "success") {
                let saleDeleteFlag = await this.deleteSaleOrder(); // 删除销售订单
                if (saleDeleteFlag == "success") {
                  this.updateExamine();
                }
              }
            }
          }
          // 为自由状态，可直接删除
        } else if (fbillflag == 2) {
          let deleteFlag = await this.deleteSaleOutStorageOrder(); // 刪除銷售出庫單
          if (deleteFlag == "success") {
            let orderUnapprove = await this.orderUnapprove(); // 销售订单弃审
            if (orderUnapprove == "success") {
              let saleDeleteFlag = await this.deleteSaleOrder(); // 删除销售订单
              if (saleDeleteFlag == "success") {
                this.updateExamine();
              }
            }
          }
        } else {
          this.updateExamine();
        }
      }
    },
    // 删除出入库单据
    deleteInOrOutStorageOrderAndGoods(id) {
      comHttp.deleteInOrOutStorageOrderAndGoods("?id=" + id).then((res) => {
        console.log(res);
      });
    },
    //是否反审核标志位
    update_audit(isAntiAudit) {
      let data = {
        id: this.Form.id,
        isAntiAudit: isAntiAudit,
      };
      console.log(data, "2222222222222");
      comHttp.updateInOrOutStorageOrder(data).then((res) => {
        console.log(res, 2222222222222);
      });
    },
    //审核标志位
    update_Mark(isOrNo) {
      let data = {
        id: this.Form.id,
        auditMark: isOrNo,
        balance: "", //审核日期
      };
      this.Form.balance = ""; //审核日期
      console.log(data, "33333333333333333");
      comHttp.updateInOrOutStorageOrder(data).then((res) => {
        console.log(res, 33333333333333);
      });
    },
    // 修改标志位 + 路由跳转，未审核，未同步
    updateExamine() {
      let data = {
        id: this.Form.id,
        auditMark: 2,
        isSynchronized: "未同步",
        isAntiAudit: "已反审核",
      };

      // 提交审核信息，修改表一数据
      comHttp.updateInOrOutStorageOrder(data).then((res) => {
        if (res.code == 200) {
          this.$message.success("反审核成功");
          setTimeout(
            this.$router.push({
              path: "/SaleOutputList",
              query: {
                Id: this.Form.id,
              },
            }),
            1000
          );
        } else {
          this.$message.success("反审核失败");
        }
      });
    },
    // 销售出库单用友查询，查询标志位
    checkSaleStatus() {
      // u8c接口
      return new Promise((resolve) => {
        axios({
          headers: {
            "Access-Control-Allow-Origin": "*",
            trantype: "code",
            "Content-Type": "application/json",
            usercode: "13355262265",
            password: "5ef208ee90e5504a7b569ebbd6342634",
            system: "test",
          },
          method: "post",
          url: "/u8cloud/api/ic/saleout/query",
          data: {
            billcode: this.Form.document, //单据号
            corp: "1001", //公司
            // corp: this.Form., //公司
            date_begin: "2021-03-29", //起始日期
            date_end: moment().format("YYYY-MM-DD"), //结束日期
          },
        }).then((response) => {
          console.log();
          let fbillflag = JSON.parse(response.data.data).datas[0].parentvo
            .fbillflag;
          resolve(fbillflag);
        });
      });
    },

    // 审核函数
    Examine() {
      // this.Form.balance = moment().format("YYYY-MM-DD");
      console.log(this.Form.balance);
      let data = {
        id: this.Form.id,
        auditMark: 1,
        balance: this.Form.balance, //审核日期
        isAntiAudit: "未反审核",
      };

      // 提交审核信息，修改表一数据
      comHttp.updateInOrOutStorageOrder(data).then((res) => {
        if (res.code == 200) {
          this.$message.success("审核成功");
          this.getRouterParam();
          this.alreadyCheckTag = false;
          // 跳转回列表页面
          this.$router.push("/SaleOutputList");
        } else {
          this.$message.success("审核失败");
        }
      });
    },

    // 同步函数
    asyncOrder() {
      let data = {
        id: this.Form.id,
        isSynchronized: "已同步",
      };

      // 提交审核信息，修改表一数据
      comHttp.updateInOrOutStorageOrder(data).then((res) => {
        if (res.code == 200) {
          this.$message.success("同步标志修改成功");
          this.getRouterParam();
        } else {
          this.$message.success("同步标志修改失败");
        }
      });
    },
    // 同步函数
    asyncCancleOrder() {
      let data = {
        id: this.Form.id,
        isSynchronized: "未同步",
      };
      // 提交审核信息，修改表一数据
      comHttp.updateInOrOutStorageOrder(data).then((res) => {
        if (res.code == 200) {
          this.$message.success("取消同步");
        } else {
          this.$message.success("同步未取消");
        }
      });
    },
    // 取消销售出库签字接口
    cancelSignature() {
      return new Promise((resolve) => {
        axios({
          headers: {
            "Access-Control-Allow-Origin": "*",
            trantype: "code",
            "Content-Type": "application/json",
            usercode: "13355262265",
            password: "5ef208ee90e5504a7b569ebbd6342634",
            system: "test",
          },
          method: "post",
          url: "/u8cloud/api/ic/saleout/unsign",

          data: {
            queryInfo: {
              billcode: this.Form.document, //单据号
              corp: "1001", //公司
              // corp: this.Form., //公司
              date_begin: "2021-03-29", //起始日期
              date_end: moment().format("YYYY-MM-DD"), //结束日期
            },
            unsignInfo: {
              coperator: this.Form.singleProducerByCode_dictText, // 制单人手机号
              date_unsign: moment().format("YYYY-MM-DD"), // 取消签字日期
            },
          },
        }).then((response) => {
          resolve(response.data.status);
        });
      });
    },
    // 删除销售出库单接口
    deleteSaleOutStorageOrder() {
      return new Promise((resolve) => {
        axios({
          headers: {
            "Access-Control-Allow-Origin": "*",
            trantype: "code",
            "Content-Type": "application/json",
            usercode: "13355262265",
            password: "5ef208ee90e5504a7b569ebbd6342634",
            system: "test",
          },
          method: "post",
          url: "/u8cloud/api/ic/saleout/delete",
          data: {
            queryInfo: {
              billcode: this.Form.document, //单据号
              date_begin: "2021-03-29",
              date_end: moment().format("YYYY-MM-DD"), //结束日期
              corp: "1001",
            },
            deleteInfo: {
              date_delete: moment().format("YYYY-MM-DD"),
              coperator: this.Form.singleProducerByCode_dictText,
            },
          },
        }).then((response) => {
          resolve(response.data.status);
        });
      });
    },
    // 删除销售订单接口
    deleteSaleOrder() {
      return new Promise((resolve) => {
        axios({
          headers: {
            "Access-Control-Allow-Origin": "*",
            trantype: "code",
            "Content-Type": "application/json",
            usercode: "13355262265",
            password: "5ef208ee90e5504a7b569ebbd6342634",
            system: "test",
          },
          method: "post",
          url: "/u8cloud/api/so/saleorder/delete",
          data: {
            queryinfo: {
              code: this.Form.document, //单据号
              date_begin: "2021-03-29",
              date_end: moment().format("YYYY-MM-DD"), //结束日期
              corp: "1001",
            },
            deleteinfo: {
              date_delete: moment().format("YYYY-MM-DD"),
              coperator: this.Form.singleProducerByCode_dictText,
            },
          },
        }).then((response) => {
          resolve(response.data.status);
        });
      });
    },
    // 销售订单弃审接口
    orderUnapprove() {
      return new Promise((resolve) => {
        axios({
          headers: {
            "Access-Control-Allow-Origin": "*",
            trantype: "code",
            "Content-Type": "application/json",
            usercode: "13355262265",
            password: "5ef208ee90e5504a7b569ebbd6342634",
            system: "test",
          },
          method: "post",
          url: "/u8cloud/api/so/saleorder/unapprove",
          data: {
            queryinfo: {
              code: this.Form.document, //单据号  , 销售订单弃审
              date_begin: "2021-03-20",
              date_end: moment().format("YYYY-MM-DD"), //结束日期
              corp: "1001",
            },
            approveinfo: {
              // date_delete: `${moment().format("YYYY-MM-DD")}`,
              approvid: this.Form.singleProducerByCode_dictText, // 出库单订单审批人
            },
          },
        }).then((response) => {
          resolve(response.data.status);
        });
      });
    },

    // 提交
    Submit() {
      let data = {
        id: this.Form.id,
        bookkeepingMark: 1,
      };
      // 提交审核信息，修改表一数据
      comHttp.updateInOrOutStorageOrder(data).then((res) => {
        if (res.code == 200) {
          this.$message.success("记账成功");
          this.alreadyRecordTag = false;
        } else {
          this.$message.success("记账失败");
        }
      });
    },

    // 保存至用友
    save_u8c() {
      console.log(
        "传递过来的数据为::::",
        this.saleForm,
        this.Form,
        this.DataSource
      );

      if (this.Form.auditMark == 1) {
        let submitForm = {};

        let submitArray = [];
        this.DataSource.forEach((element) => {
          let arrayForm = {
            ccurrencytypeid: this.saleForm.currency_dictText, //币种√
            nexchangeotobrate: this.saleForm.nexchangeotobrate, //折本汇率 √
            cadvisecalbodyid: this.saleForm.bodycode, //发货库存组织 √
            // cconsigncorpid: this.saleForm.pkCorp, //发货公司 √
            cconsigncorpid: "1001", //发货公司 √

            cbodywarehouseid: element.depotNo, //发货仓库
            cinventoryid: element.inventoryNo, //存货ID√
            nnumber: element.quantity, //数量√
            noriginalcurprice: element.noriginalcurprice, //无税单价√
            ntaxrate: this.saleForm.ntaxrate * 100, //税率 √
            noriginalcurtaxprice: element.noriginalcurtaxprice, // 含税单价 √
            noriginalcursummny: element.noriginalcursummny, // 价税合计（原币）√
            nsummny: element.nsummny, //本币价税合计 √
            nnetprice: element.nnetprice, //本币无税净价 √
            ntaxprice: element.ntaxprice, //本币含税单价 √
            blargessflag: element.giveaway == "是" ? "Y" : "N", //是否赠品√

            // vfree2: moment(this.saleForm.sailingSchedule).format(
            //   "YYYY-MM-DD"
            // ), //船期-自定义项2
          };
          submitArray.push(arrayForm);
        });

        submitForm = {
          parentvo: {
            cbiztype: this.Form.cbiztypeByCode_dictText, //业务流程 ✔
            ccustomerid: this.Form.clientIdByCode_dictText, //客户 ✔
            cdispatcherid: this.Form.sendReceiveTypeId, // 收发类别  ✔
            cdeptid: this.saleForm.deptNumber, // 部门名称dept ✔
            coperatorid: this.Form.singleProducerByCode_dictText, //制单人-传手机号 ✔
            cemployeeid: this.saleForm.workNo, //业务员 ✔
            cwarehouseid: this.Form.depotNo, //仓库  ✔
            ndiscountrate: this.saleForm.ndiscountrate, //整单折扣 ✔
            // dbilldate: moment(this.Form.documentDate).format("YYYY-MM-DD"), //单据日期✔
            dbilldate:moment(this.Form.document_date).format(
              "YYYY-MM-DD"),
            vreceiptcode: this.Form.document, //单据号✔
            csalecorpid: this.saleForm.listThree[0].vsalestrucode, // 销售组织 ✔
            ccalbodyid: this.saleForm.listThree[0].bodycode, // 库存组织 ✔
            // pk_corp: this.saleForm.pkCorp, // 公司 ✔
            pk_corp: "1001",
            bretinvflag: "N", //退货标记（Y / N）
          },
          childrenvo: submitArray,
        };

        axios({
          headers: {
            "Access-Control-Allow-Origin": "*",
            trantype: "code",
            "Content-Type": "application/json",
            usercode: "13355262265",
            password: "5ef208ee90e5504a7b569ebbd6342634",
            system: "test",
          },
          method: "post",
          url: "/api/u8cloud/api/so/saleorder/saveapprove",
          data: {
            saleorder: submitForm,
          },
        }).then((response) => {
          console.log(response);
          if (response.data.status == "success") {
            this.$message.success("U8C销售出库单新增成功！");
            this.asyncOrder(); // 同步
            // 更新单据的是否同步标志位，更新为已同步。
          } else {
            this.$message.error(response.data.errormsg);
          }
        });
      } else {
        this.$message.error("请先进行审核，再同步至u8c！");
      }

      // if(this.DataSource[0].)
      // if (this.dataList[0].auditMark_dictText == "已审核") {
      //
      //       this.arr.push(data);
      //       console.log("this.arr", this.arr);
      //     }
      //     let ayyany = {
      //
      //     };
      //     this.ayyanyany.push(ayyany);
      //   //U8c调用销售订单接口
      //
      // } else {
      //
    },

    // 获取路由跳转参数
    getRouterParam() {
      console.log("查询参数:::", this.$route.query.Id);

      // 通过出入库id 查询出入库信息
      if (typeof this.$route.query.Id == "undefined") {
        console.log("常规跳转");
      } else {
        this.setInitInfo(this.$route.query.Id);
      }
    },

    // 路由跳转,设置初始化信息
    setInitInfo(id) {
      comHttp
        .getInOrOutStorageOrderAndGoodsInfoById("?id=" + id)
        .then((res) => {
          console.log("销售出库详情:::::", res);

          this.ayyanyany = [];
          this.DataSource = [];

          // 是否审核
          if (res.result.list[0].auditMark == 1) {
            //审核
            this.alreadyCheckTag = false;
            this.AntcanCheck = false;
            if (
              res.result.list[0].inspector !== this.$store.state.user.info.id
            ) {
              this.AntcanCheck = true;
            }
            console.log("this.Form.AntcanCheck", this.AntcanCheck);
          } else {
            //未审核
            this.alreadyCheckTag = true;
            this.AntcanCheck = true;
            // if (
            //   res.result.list[0].inspector == this.$store.state.user.info.id
            // ) {
            //   // 审核人 == 当前登录人
            //   this.Form.AntcanCheck = true;
            // }
          }

          // 是否记账
          if (res.result.list[0].bookkeepingMark == 1) {
            this.alreadyRecordTag = false;
          } else {
            this.alreadyRecordTag = true;
          }

          if (res.result.list[0].isSynchronized == "已同步") {
            this.alreadyAsyncTag = false;
          } else {
            this.alreadyAsyncTag = true;
          }

          this.otherId = res.result.list[0].otherId; // 表一 Id
          this.Form = {
            id: res.result.list[0].otherId, // 表一 Id
            document: res.result.list[0].document, // 单据号
            document_date: res.result.list[0].documentDate, // 单据日期
            department: res.result.list[0].deptId_dictText, // 销售部门
            client: res.result.list[0].clientId_dictText, // 客户

            depotName: res.result.list[0].storname, // 发货仓库

            cwhsmanagerid_dictText: res.result.list[0].cwhsmanagerid_dictText, // 库管员
            pkCalbody_dictText: res.result.list[0].pkCalbody_dictText, // 库存组织

            sendReceiveType: res.result.list[0].sendReceiveType_dictText, // 收发类别
            sendReceiveTypeId: res.result.list[0].sendReceiveType, // 收发类别
            cbiztype_dictText: res.result.list[0].cbiztype_dictText, // 收发类别

            cbiztypeByCode_dictText: res.result.list[0].cbiztypeByCode_dictText, // 业务流程

            responsiblePerson: res.result.list[0].responsiblePerson_dictText, // 负责人
            inspector: res.result.list[0].inspector_dictText, // 审核人
            singleProducer: res.result.list[0].singleProducer_dictText, // 制单人
            singleProducerByCode_dictText:
              res.result.list[0].singleProducerByCode_dictText, // 制单人手机号
            balance: res.result.list[0].balance, //审核日期

            clientIdByCode_dictText: res.result.list[0].clientIdByCode_dictText, // 客戶

            auditMark: res.result.list[0].auditMark, // 是否审核（1,已审核,2,未审核）
            isSynchronized: res.result.list[0].isSynchronized, // 是否同步到用友
            isAntiAudit: res.result.list[0].isAntiAudit, //是否反审核
          };

          for (let i = 0; i < res.result.list.length; i++) {
            let data = {
              key: i + 1,
              id: res.result.list[i].twoId, // 表二Id
              otherId: res.result.list[i].otherId,
              depotNo: res.result.list[i].storcode, // 仓库编码
              depotName: res.result.list[i].storname, // 仓库名称
              depotLocation: res.result.list[i].depotLocation, // 库位
              position: res.result.list[i].position, // 仓位
              position_dictText: res.result.list[i].position_dictText, // 仓位
              storageUnit: res.result.list[i].storageUnit_dictText, // 所属单位
              inventoryNo: res.result.list[i].invcode, // 存货编码
              inventoryName: res.result.list[i].invname, // 存货名称
              standardModel: res.result.list[i].invspec, // 规格型号
              unit: res.result.list[i].measname, // 单位
              auxiliaryUnit: res.result.list[i].auxiliaryUnit, // 辅助单位
              quantity: res.result.list[i].quantity, // 数量
              sourceNumber: res.result.list[i].sourceNumber, // 源单单号
              batchNumber: res.result.list[i].batchNumber, // 批次号
              giveaway: res.result.list[i].giveaway_dictText, // 是否赠品
              deliveryDate: res.result.list[i].deliveryDate, // 出库日期
              remark: res.result.list[i].remarks, // 备注
            };
            this.DataSource.push(data);
          }
          this.getPrint();

          this.dataList = res.result.list;
          // 查看销售订单
          this.getSaleInfoById(res.result.list[0].saleOrderAddId);
        });
    },

    // 获取销售订单信息
    getSaleInfoById(id) {
      comHttp.getSaleInfoById("?id=" + id).then((res) => {
        console.log("查询到的销售订单信息", res.result.object);
        // 拼接数据
        this.saleForm = res.result.object;

        for (let i = 0; i < this.DataSource.length; i++) {
          res.result.object.list.forEach((element) => {
            if (element.inventoryNo == this.DataSource[i].inventoryNo) {
              this.$set(
                this.DataSource[i],
                "amountOfOriginalCurrency",
                element.amountOfOriginalCurrency
              );

              this.$set(this.DataSource[i], "money", element.money);

              this.$set(this.DataSource[i], "nnetprice", element.nnetprice);

              this.$set(
                this.DataSource[i],
                "noriginalcurprice",
                element.noriginalcurprice
              );
              this.$set(
                this.DataSource[i],
                "noriginalcursummny",
                element.noriginalcursummny
              );
              this.$set(
                this.DataSource[i],
                "noriginalcurtaxprice",
                element.noriginalcurtaxprice
              );
              this.$set(this.DataSource[i], "nsummny", element.nsummny);
              this.$set(this.DataSource[i], "ntaxprice", element.ntaxprice);
              this.$set(
                this.DataSource[i],
                "unitMeasurement",
                element.unitMeasurement
              );
              this.$set(this.DataSource[i], "unitPrice", element.unitPrice);
              this.$set(
                this.DataSource[i],
                "unitPriceOriginalCurrency",
                element.unitPriceOriginalCurrency
              );
            }
          });
        }

        console.log("123124", this.DataSource);
      });
    },

    // this.u8c_array数组根据仓库编码筛选，将相同的仓库编码放在一个数组里
    sortArr(arr, str) {
      var newArr = [],
        newArrItem = [],
        // 临时变量
        tempArr = [];
      // 按照特定的参数将数组排序将具有相同值的排在一起
      arr = arr.sort(function (a, b) {
        var s = a[str],
          t = b[str];

        return s < t ? -1 : 1;
      });

      if (arr.length) {
        tempArr = arr[0][str];
      }

      // 将相同类别的对象添加到统一个数组
      for (var i in arr) {
        if (arr[i][str] === tempArr) {
          console.log("tempArr", tempArr);
          newArrItem.push(arr[i]);
        } else {
          tempArr = arr[i][str];
          newArr.push(newArrItem);
          newArrItem = [arr[i]];
        }
      }
      // 将最后的内容推出新数组
      newArr.push(newArrItem);
      this.u8c_array = newArr;
      console.log("u8c_arr", this.u8c_array);
    },

    getPrint() {
      this.printDataSource = [];
      let sum = 0;
      for (let i = 0; i < this.DataSource.length; i++) {
        let data = {
          // inventoryNo: this.DataSource[i].inventoryNo,
          inventoryName: this.DataSource[i].inventoryName,
          standardModel: this.DataSource[i].standardModel,
          unit: this.DataSource[i].unit,
          quantity: this.DataSource[i].quantity,
          remark: this.DataSource[i].remark,
        };
        sum = sum + this.DataSource[i].quantity;
        this.printDataSource.push(data);
      }

      // 计算合计
      let endData = {
        inventoryName: "合计",
        standardModel: "",
        unit: "",
        quantity: sum,
        remark: "",
      };
      this.printDataSource.push(endData);
    },

    // 打印功能实现
    goPrint() {
      const style = "@page {margin:0 10mm}; "; // 去掉页眉和页脚
      printJS({
        style, // 添加去掉页眉页脚样式
        targetStyles: ["*"],
        type: "html", // 类型
        printable: "printCons", // 表格内容
        maxWidth: 1000,
        // 表头
        header: ` 
        <h3  style="
            padding-top:10px;
            text-align: center;
            height: 40px;
            line-height: 40px;
            font-size: 20px;
          ">销售出库单</h3>
       `,
      });
    },
  },
};
</script>

<style>
.print-table table td,
.print-table table th,
.print-table table tr {
  border: 1px solid black;
}
.print-table table tr {
  height: 30px;
}
.print-table table th {
  height: 30px;

  font-weight: normal;
}
.print-table table {
  height: 30px;
  font-weight: normal;
}
</style>
